package com.hbxy.favorite.controller;

import com.hbxy.favorite.domain.Favorites;
import com.hbxy.favorite.domain.User;
import com.hbxy.favorite.resault.ResponseBo;
import com.hbxy.favorite.service.FavoritesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class FavoritesController {
    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private  FavoritesService favoritesService;
    /**
     * 获取收藏夹
     * @return
     */
    @RequestMapping("/getFavorites")
    @ResponseBody
    public ResponseBo getFavorites(@RequestBody User user){

        ResponseBo responseBo = favoritesService.getFavorites(user);
        return  responseBo;
    }
    /**
     * 添加收藏夹
     */
    @RequestMapping("/addfavorites")
    @ResponseBody
    public ResponseBo addFavorites(@RequestBody  Favorites favorites){

        ResponseBo responseBo = favoritesService.addFavorites( favorites);
        return  responseBo;
    }
    /**
     * 修改收藏夹
     */
    @ResponseBody
    public  ResponseBo updateFavorites(@RequestBody Favorites favorites){

        ResponseBo responseBo = favoritesService.updateFavorites( favorites);

        return  responseBo;
    }
    /**
     * 删除收藏夹
     */
    @RequestMapping("/deleteFavorite")
    @ResponseBody
    public ResponseBo deleteFavorites(@RequestBody Favorites favorites){

         int flag = favoritesService.deleteFavorites( favorites);
         log.info("-----------"+flag);
         if(flag == 1)
            return  ResponseBo.ok();
         else
             return ResponseBo.error();
    }

}
